home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <stream.h>
- #include <assert.h>
- #include <speech/CharString.h>
- #include <speech/Recognizer.h>
- #include <speech/Word.h>
- #include <speech/WordCallbackBindings.h>
- #include <speech/Vocabulary.h>
- #include <speech/Condition.h>
- #include <speech/Event.h>
- #include <speech/Error.h>
- #include <speech/Shorthand.h>
-
- void doThis( const Event* event, void* /*v*/ )
- { cout << "do this called with " << event->type() << "\n" << flush ; }
- void doThat( const Event* event, void* /*v*/ )
- { cout << "do that called with " << event->type() << "\n" << flush ; }
- void doTheOther( const Event* event, void* /*v*/ )
- { cout << "do the other called with " << event->type() << "\n" << flush ; }
-
- void usage( const char* const /*progName*/ )
- { cerr << "progName <word> <word2>\n" << flush ; exit( -1 ) ; }
-
- int main( int argc, char* argv[] )
- {
- char* wordName1 ;
- char* wordName2 ;
- char* wordName3 ;
-
- char* applicationClass = "Recognize" ;
- char* applicationName = argv[0] ;
-
- XrmDatabase xrmDatabase // toolkit-dependent
- = XrmGetFileDatabase( CharString( getenv( "HOME" ) ) + "/.Xdefaults" ) ;
-
- Recognizer recognizer( applicationClass, applicationName, xrmDatabase,
- "", // default display, program name
- Recognizer::RecognitionInterest // get recognition events and all others
- | Recognizer::RejectionInterest
- | Recognizer::AmbiguousInterest
- | Recognizer::ErrorInterest ) ;
- assert( recognizer.status( ) == Error::OK ) ;
-
- unsigned char swapConditionsUsingVocabularies = 0 ;
-
- for( long i = 1 ; i < argc ; i++ )
- if( argv[i][0] == '-' )
- switch( argv[i][1] )
- {
- case 's': i++ ; swapConditionsUsingVocabularies=1 ; break ;
- case 'v': i++ ; /* ;*/ break ;
- case 'd': i++ ; /* ;*/ break ;
- default: usage( argv[0] ) ; break ;
- }
- else
- break ;
-
- wordName1 = "doThis" ;
- wordName2 = "doThat" ;
- wordName3 = "doTheOther" ;
-
- if( i < argc )
- wordName1 = argv[i++] ;
- if( i < argc )
- wordName2 = argv[i++] ;
- if( i < argc )
- wordName3 = argv[i++] ;
-
-
- // words with global focus
-
- #ifdef OLD
- ActionFunctionBinding globalActionFunctionBindings[] = {
- { "doThis", doThis, (void*)0 },
- { "doThat", doThat, (void*)0 },
- { (char*)0, (CallbackFunctionPointer)0, (void*)0 },
-
- globalActionFunctionBindings[0].actionNameValue = wordName1 ;
- globalActionFunctionBindings[1].actionNameValue = wordName2 ;
- } ;
- #else
- ActionFunctionBinding globalActionFunctionBindings[] = {
- ActionFunctionBinding( "doThis", doThis, (void*)0 ),
- ActionFunctionBinding( "doThat", doThat, (void*)0 ),
- ActionFunctionBinding( (char*)0, (CallbackFunctionPointer)0, (void*)0 ),
- } ;
- #endif
-
- Vocabulary* globalWords ;
- recognizer.newWords( globalActionFunctionBindings,
- Condition( Condition::Global ),
- globalWords ) ;
- if( recognizer.status() != Error::OK )
- cerr << "trouble loading global words\n" << flush ;
-
-
- // words with window focus
-
- #ifdef OLD
- ActionFunctionBinding localActionFunctionBindings[] = {
- { "doTheOther", doTheOther, (void*)0 },
- { (char*)0, (CallbackFunctionPointer)0, (void*)0 },
- } ;
-
- localActionFunctionBindings[0].actionNameValue = wordName3 ;
- #else
- ActionFunctionBinding localActionFunctionBindings[] = {
- ActionFunctionBinding( "doTheOther", doTheOther, (void*)0 ),
- ActionFunctionBinding( (char*)0, (CallbackFunctionPointer)0, (void*)0 ),
- } ;
- #endif
-
- // toolkit dependent
- void* v = "client data" ;
- int screen = DefaultScreen( recognizer.dpy() ) ;
- Window root = RootWindow( recognizer.dpy(), screen ) ;
- long white = WhitePixel( recognizer.dpy(), screen ) ;
- long black = BlackPixel( recognizer.dpy(), screen ) ;
- Window window = XCreateSimpleWindow( recognizer.dpy(), root,
- 100, 100, 100, 100, 1, white, black ) ;
- XMapWindow( recognizer.dpy(), window ) ;
-
- Vocabulary* localWords ;
- recognizer.newWords( localActionFunctionBindings,
- Condition( window ),
- localWords ) ;
- if( recognizer.status() != Error::OK )
- cerr << "trouble loading local words\n" << flush ;
-
- #ifdef TODO
- gw.enable( win ) ;
- lw.enable( Global ) ;
- #endif
-
- // vocabulary usage
- if( swapConditionsUsingVocabularies )
- {
- cerr << "swapping conditions using vocabularies\n" << flush ;
-
- {
- Vocabulary vocabulary( recognizer ) ;
- Word* word ;
- for( long i = globalWords->first() ;
- globalWords->get( i, word ) ;
- i = globalWords->next( i ) )
- vocabulary.add( *word ) ;
- Condition localCondition( window ) ;
- vocabulary.enable( localCondition ) ;
- }
-
- {
- Vocabulary vocabulary( recognizer ) ;
- Word* word ;
- for( long i = localWords->first() ;
- localWords->get( i, word ) ;
- i = localWords->next( i ) )
- vocabulary.add( *word ) ;
- Condition globalCondition( Condition::Global ) ;
- vocabulary.enable( globalCondition ) ;
- }
- }
-
- if( globalWords ) delete globalWords ;
- if( localWords ) delete localWords ;
-
- // toolkit-dependent modification here
- XEvent event ;
- do
- {
- XNextEvent( recognizer.dpy(), &event ) ;
- cout << "event type = " << event.type << "\n" << flush ;
- if( recognizer.isSpeechEvent( &event ) )
- recognizer.processEvent( &event ) ;
- else
- ; // process as other/normal event
- } while( event.type != DestroyNotify ) ; // just to get rid of warning
-
- XrmDestroyDatabase( xrmDatabase ) ;
-
- return recognizer.status( ) ;
- }
-